//@author A0087191Y
package net.mysoc.w111j.service.actions;

import net.mysoc.w111j.model.Expense;
import net.mysoc.w111j.model.User;

/**
 * An {@code Action} to undo the modification of an {@code Expense}.
 */
public class ModifyExpenseAction implements Action {
    private final User user;
    private final Expense oldExpense;
    private String status;

    public ModifyExpenseAction(User user, Expense oldExpense) {
        this.user = user;
        this.oldExpense = oldExpense;
        setStatus(oldExpense);
    }

    @Override
    public void undo() {
        user.updateExpense(oldExpense);
    }

    private void setStatus(Expense expense) {
        status = "Modified expense: id." + expense.getId() + " " + expense.getName();
    }

    protected void setStatusString(String status) {
        this.status = status;
    }

    @Override
    public String getStatus() {
        return status;
    }
}
